package com.matt.sooncleaner.junk

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.matt.sooncleaner.R
import com.matt.sooncleaner.arch.ArchActivity
import com.matt.sooncleaner.databinding.ActivityJunkCleanBinding


class JunkActivity : ArchActivity<ActivityJunkCleanBinding>(), JunkScanFragment.OnJunScanListener,
    JunkScanResultFragment.StartCleanListener, CleanProgressFragment.CleanFinishListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val scanFragment = JunkScanFragment()
        showFragment(scanFragment)
    }

    override fun onScanFinish(junkScanResult: MutableList<JunkBean>) {
        val resultFragment = JunkScanResultFragment()
        resultFragment.setJunkResult(junkScanResult)
        showFragment(resultFragment)
    }

    override fun startClean(result: MutableList<JunkBean>) {
        val cleanProgressFragment = CleanProgressFragment()
        cleanProgressFragment.setJunkResult(result)
        showFragment(cleanProgressFragment)
    }

    override fun onCleanFinish() {
        val cleanCompletedFragment = CleanCompletedFragment()
        showFragment(cleanCompletedFragment)
    }

    private fun showFragment(fragment: Fragment) {
        supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commitNowAllowingStateLoss()
    }
}